package com.sunwayworld.common.hibernate;

import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Session;
import com.sunwayworld.common.utils.SplitPage;
import com.sunwayworld.common.utils.VCommList;

public class BaseDaoSupport extends SpringHibernateDao {
	
	
	protected VCommList getVCommList(Class _class, Map map, SplitPage spage) {
		Session session = null;
		try {

			session = this.getSession();

			Criteria criteria = session.createCriteria(_class);
			criteria = HibernateAssert.copyCriteria(_class, map, criteria);
			int nCount = 0;
			List list = null;
			if (null == spage) {
				list = criteria.list();
				nCount = list.size();
				return HibernateAssert.fillCommList(list, spage, nCount);
			}
			list = criteria.list();
			nCount = list.size();
			list = null;
			int _first = (spage.getCurrPage() - 1) * spage.getNumPerPage();
			int _max = spage.getNumPerPage();

			criteria.setFirstResult(_first);
			criteria.setMaxResults(_max);
			list = criteria.list();
			return HibernateAssert.fillCommList(list, spage, nCount);
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		} finally {
			this.releaseSession(session);
		}
	}

	
}
